package com.ihcy.base.model.vo.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ihcy.base.enums.PositioneEnum;
import com.ihcy.base.model.entity.User;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserResponse {
    private Long id;

    private String employeeNo;

    private String userName;

    private String phone;

    private String cardNo;

    private PositioneEnum position;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedTime;

    public static UserResponse build(User user) {
        return UserResponse.builder()
                .id(user.getId())
                .employeeNo(user.getEmployeeNo())
                .userName(user.getUserName())
                .phone(user.getPhone())
                .cardNo(user.getCardNo())
                .position(user.getPosition())
                .createdTime(user.getCreatedTime())
                .updatedTime(user.getUpdatedTime())
                .build();
    }

    public static List<UserResponse> buildList(List<User> userList) {
        return userList.stream().map(UserResponse::build).collect(Collectors.toList());
    }
}
